/**
 * Subclass van ui_AddRuleDialog
 */
#include "settingsdialog.h"
#include <QDebug>
#include <QFileDialog>
#include <iostream.h>

/**
 * Constructor
 */
SettingsDialog::SettingsDialog(QDialog *parent) : QDialog(parent)
{
	setupUi(this);
	this->setWindowModality(Qt::ApplicationModal);
}
void SettingsDialog::fillForm(Value *settings)
{
	
	downlinkRateLineEdit->setText(QString().fromStdString(((Value)*settings)["downlink"].asString()));
	uplinkRateLineEdit->setText(QString().fromStdString(((Value)*settings)["uplink"].asString()));
	defaultRateLineEdit->setText(QString().fromStdString(((Value)*settings)["default_bucket_rate"].asString()));
	defaultPriorityLineEdit->setText(QString().fromStdString(((Value)*settings)["default_priority"].asString()));
	deviceLineEdit->setText(QString().fromStdString(((Value)*settings)["device"].asString()));
	ifbLineEdit->setText(QString().fromStdString(((Value)*settings)["ifb"].asString()));
	tcCmdLineEdit->setText(QString().fromStdString(((Value)*settings)["tc_cmd"].asString()));
	suCmdLineEdit->setText(QString().fromStdString(((Value)*settings)["su_cmd"].asString()));
}
void SettingsDialog::accept()
{
	Value settings=Value(objectValue);
	settings["downlink"]=downlinkRateLineEdit->text().toStdString();
	settings["uplink"]=uplinkRateLineEdit->text().toStdString();
	settings["default_bucket_rate"]=defaultRateLineEdit->text().toStdString();
	settings["default_priority"]=defaultPriorityLineEdit->text().toStdString();
	settings["device"]=deviceLineEdit->text().toStdString();
	settings["ifb"]=ifbLineEdit->text().toStdString();
	settings["tc_cmd"]=tcCmdLineEdit->text().toStdString();
	settings["su_cmd"]=suCmdLineEdit->text().toStdString();
	settings["burst"]="1500";
	this->hide();
	emit newSettings(settings);
}
